package me.youline.dataServer.service.pubMsg;

import java.util.Date;
import java.util.List;

import com.google.common.base.Function;
import com.google.common.collect.Lists;

import me.youline.dataServer.entity.PublicMessage.MsgStatus;
import me.youline.dataServer.entity.PublicMessageIndex;

public class PubMsgIndexHelper {

	public PublicMessageIndex getMsgIndex(Long msgId, PubMsgIndexConfig config) {
		PublicMessageIndex index = new PublicMessageIndex(msgId,
				config.getDefaultCreatorId(), config.getDefaultDisplayUrl(),
				MsgStatus.publicMsg, new Date());
		return index;
	}

	public List<PublicMessageIndex> getMsgIndexs(List<Long> msgIds,
			PubMsgIndexConfig config) {
		List<PublicMessageIndex> list = Lists.newArrayList();
		for (Long id : msgIds) {
			list.add(this.getMsgIndex(id, config));
		} 
		return list;
	}

	public List<Long> getMsgIdsFromIndexs(List<PublicMessageIndex> list) {
		return Lists.transform(list, new Function<PublicMessageIndex, Long>() {

			@Override
			public Long apply(PublicMessageIndex input) {
				return input.getMsgId();
			}

		});

	}

	public static class PubMsgIndexConfig {
		private Long defaultCreatorId;
		private String defaultDisplayUrl;

		public PubMsgIndexConfig(Long defaultCreatorId, String defaultDisplayUrl) {
			this.defaultCreatorId = defaultCreatorId;
			this.defaultDisplayUrl = defaultDisplayUrl;
		}

		public Long getDefaultCreatorId() {
			return defaultCreatorId;
		}

		public void setDefaultCreatorId(Long defaultCreatorId) {
			this.defaultCreatorId = defaultCreatorId;
		}

		public String getDefaultDisplayUrl() {
			return defaultDisplayUrl;
		}

		public void setDefaultDisplayUrl(String defaultDisplayUrl) {
			this.defaultDisplayUrl = defaultDisplayUrl;
		}

	}

}
